<template>
	<view class="mask">
		<view class="popup">
			<view class="pic">
				<image @click="closePopUp" class="icon-close" src="/static/icons/details_bar_popup_return@3x.png">
				</image>

				<view class="good-info">
					<!-- 商品图片展示 -->
					<view class="">
						<image :src="goodsDetail.imgUrl" class="good-pic"></image>
					</view>
					<!-- 商品名称价格 -->
					<view class="goods-name-price">
						<view class="goods-title">
							{{goodsDetail.name}}
						</view>
						<view class="goods-jiage">
							￥{{goodsDetail.price}}
						</view>
					</view>
				</view>
			</view>

			<!-- 购买数量增减 -->
			<view class="buy-num">
				<view class="buy-num-title">
					购买数量
				</view>
				<!-- 数量增加组件 -->
				<view class="increase-decrease">
					<uni-number-box :min="1" :value="num" @change="numChangeHandle"></uni-number-box>
				</view>
			</view>
			<!-- 确认按钮 -->
			<view class="confirm-btn" @click="confirmBuy">
				确认
			</view>
		</view>
	</view>
</template>

<script>
	import {
		mapState,
		mapMutations
	} from 'vuex'
	export default {
		name: "my-popup",
		props: {
			goodsDetail: {
				type: Object,
				default: {}
			}
		},
		data() {
			return {
				num: 1
			};
		},
		onLoad() {

		},
		methods: {
			// 立即购买 生成订单
			async confirmBuy() {
				// 判断库存是否充足
				console.log(this.goodsDetail.stock)
				if (this.goodsDetail.stock == 0 || this.goodsDetail.stock == '0') {
					uni.$showMsg('库存不足！')
				} else {
					if (JSON.stringify(this.userInfo) !== '{}') {
						uni.navigateTo({
							url: '/subpkg/cart-order/cart-order?num=' + this.num
						})
					} else {
						uni.navigateTo({
							url:'/subpkg/login/login'
						})
						uni.$showMsg('请先登录!')
					}
					uni.setStorageSync('detail', JSON.stringify(this.goodsDetail))

				}
			},
			closePopUp() {
				this.$emit('close')
			},
			numChangeHandle(val) {
				// console.log(val)
				this.num = +val
			}
		},
		computed: {
			...mapState('m_user', ['userInfo'])
		}
	}
</script>

<style lang="scss">
	.mask {
		width: 100%;
		height: 100%;
		position: fixed;
		bottom: 0;
		left: 0;
		right: 0;
		top: 0;
		background-color: rgba(0, 0, 0, .6);
	}

	.popup {
		padding: 0 25rpx;
		padding-top: 15rpx;
		box-sizing: border-box;
		z-index: 999;
	}

	.icon-close {
		width: 52rpx;
		height: 52rpx;
		margin-left: 639rpx;
		margin-top: 17rpx;
	}

	.goods-name-price {
		width: 545rpx;
		padding-left: 17rpx;
		box-sizing: border-box;
	}

	.good-pic {
		width: 180rpx !important;
		height: 180rpx !important;
		border-radius: 12rpx;
		// margin-right: 17rpx;
	}

	.goods-title {
		height: 95rpx;
		overflow: hidden;
		text-overflow: ellipsis;
		margin-bottom: 25rpx;
		margin-top: 10rpx;
		overflow: hidden;
	}

	.goods-jiage {
		font-size: 42rpx;
		font-weight: bold;
		color: #FF1111;
	}

	.good-info {
		display: flex;
	}


	.buy-num {
		display: flex;
		height: 170rpx;
		line-height: 170rpx;

		.buy-num-title {
			font-size: 36rpx;
			font-weight: bold;
			color: #333333;
			margin-right: 300rpx;
		}

		.increase-decrease {
			padding-top: 50rpx;
			box-sizing: border-box;

		}
	}

	.confirm-btn {
		width: 701rpx;
		height: 78rpx;
		line-height: 78rpx;
		text-align: center;
		background: #d80e0e;
		border-radius: 8rpx;
		margin-top: 20rpx;
		font-size: 34rpx;
		font-weight: 500;
		color: #FFFFFF;
	}
</style>
